package com.gxa.controller;

import com.gxa.common.R;
import com.gxa.pojo.User;
import com.gxa.service.UserService;
import com.gxa.service.impl.UserServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@Controller
//@SessionAttributes(value={"user"},types={Integer.class})
public class UserController {

    private UserService userService = new UserServiceImpl();

    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public String login(String username, String password, ModelMap modelMap){
        modelMap.put("user",username);
        return "index";
    }

    @RequestMapping(value = "/register",method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    @ResponseBody
//    public R addUser(@RequestBody User user){//@RequestBody接收json数据
    public R addUser(@RequestBody Map map,@RequestHeader("token") String token){//@RequestBody接收json数据
        System.out.println(map);
        System.out.println(token);
//        int i = 1 / 0;
        int i = Integer.parseInt("zhangsan");
        R  r = userService.addUser(map);
        return r;
    }

    @RequestMapping(value="/getcookie",method = RequestMethod.GET)
    public String getReg2(@CookieValue(value = "JSESSIONID") String jsessionid) {
        System.out.println(jsessionid);
        return "";
    }

    @RequestMapping(value="/getheader",method = RequestMethod.GET)
    public String getReg2(@RequestHeader("User-Agent") String userAgent,
                          @RequestHeader(value="Accept") String[] accepts) {
        System.out.println(userAgent);
        System.out.println(accepts);
        int i = 1 / 0; //500
        return "login";
    }


}
